class Student:
    def __init__(self, name, student_id, score):
        self.name = name
        self.student_id = student_id
        self.score = score


class StudentManagementSystem:
    def __init__(self):
        self.students = {}

    def add_student(self, name, student_id, score):
        """添加学生信息"""
        if student_id in self.students:
            return False, "该学号已存在"

        try:
            score = float(score)
            if score < 0 or score > 100:
                return False, "成绩必须在0-100之间"
        except ValueError:
            return False, "成绩必须是数字"

        self.students[student_id] = Student(name, student_id, score)
        return True, "添加成功"

    def query_student(self, student_id):
        """查询学生信息"""
        if student_id not in self.students:
            return None
        student = self.students[student_id]
        return {
            "name": student.name,
            "student_id": student.student_id,
            "score": student.score
        }

    def display_all_students(self):
        """显示所有学生信息"""
        if not self.students:
            return []

        return [{
            "name": student.name,
            "student_id": student.student_id,
            "score": student.score
        } for student in self.students.values()]


def main():
    sms = StudentManagementSystem()

    while True:
        print("\n=== 学生信息管理系统 ===")
        print("1. 添加学生")
        print("2. 查询学生")
        print("3. 显示所有学生")
        print("4. 退出")

        choice = input("请选择操作 (1-4): ")

        if choice == "1":
            name = input("请输入学生姓名: ")
            student_id = input("请输入学号: ")
            score = input("请输入成绩: ")
            success, message = sms.add_student(name, student_id, score)
            print(message)

        elif choice == "2":
            student_id = input("请输入要查询的学号: ")
            student = sms.query_student(student_id)
            if student:
                print(f"\n学生信息:")
                print(f"姓名: {student['name']}")
                print(f"学号: {student['student_id']}")
                print(f"成绩: {student['score']}")
            else:
                print("未找到该学生")

        elif choice == "3":
            students = sms.display_all_students()
            if students:
                print("\n所有学生信息:")
                for student in students:
                    print(f"\n姓名: {student['name']}")
                    print(f"学号: {student['student_id']}")
                    print(f"成绩: {student['score']}")
            else:
                print("暂无学生信息")

        elif choice == "4":
            print("感谢使用，再见！")
            break

        else:
            print("无效的选择，请重试")


if __name__ == "__main__":
    main()
